<?php

use App\Helpers\CSRF;
use App\Helpers\HTML;
use App\Helpers\URL;

if ($event !== "contactUpdate_{$contactId}") { ?>
<?php $app->render('templates/dashboard_open', ['app' => $app, 'title' => 'Editar contacto']) ?>
<?php } ?>
<div id="<?= "contactUpdate_{$contactId}" ?>" class="card col-4">
  <?php if (isset($error)) { ?>
    <?php $app->render('components/error', ['error' => $error]) ?>
  <?php } ?>
  <form action="<?= URL::event(['contacts', 'update', $contactId], null, "contactUpdate_{$contactId}") ?>" method="post" enctype="multipart/form-data" target=htmz>
    <input type="hidden" name="<?= CSRF::getVarname() ?>" value="<?= $app->local(CSRF::getVarname()) ?>">
    <p>
      <label for="fullname">Nombre</label>
      <input type="text" name="fullname" id="fullname" placeholder="Juan Pérez" value="<?= HTML::esc($values['fullname']) ?>" class="<?= $status['fullname'] ?>">
      <small class="text-error"><?= HTML::esc($validations['fullname']) ?></small>
    </p>
    <p>
      <label for="phone">Teléfono</label>
      <input type="tel" name="phone" id="phone" placeholder="1-(555)-555-5555" value="<?= HTML::esc($values['phone']) ?>" class="<?= $status['phone'] ?>">
      <small class="text-error"><?= HTML::esc($validations['phone']) ?></small>
    </p>
    <p>
      <label for="email">Correo</label>
      <input type="email" name="email" id="email" placeholder="juan.perez@email.com" value="<?= HTML::esc($values['email']) ?>" class="<?= $status['email'] ?>">
      <small class="text-error"><?= HTML::esc($validations['email']) ?></small>
    </p>
    <p>
      <label for="company">Empresa</label>
      <input type="text" name="company" id="company" placeholder="Tech Solutions S.A. de C.V." value="<?= HTML::esc($values['company']) ?>" class="<?= $status['company'] ?>">
      <small class="text-error"><?= HTML::esc($validations['company']) ?></small>
    </p>
    <p>
      <label for="website">Sitio web</label>
      <input type="url" name="website" id="website" placeholder="https://www.techsolutions.com" value="<?= HTML::esc($values['website']) ?>" class="<?= $status['website'] ?>">
      <small class="text-error"><?= HTML::esc($validations['website']) ?></small>
    </p>
    <p>
      <label for="birthday">Cumpleaños</label>
      <input type="date" name="birthday" id="birthday" value="<?= HTML::esc($values['birthday']) ?>" class="<?= $status['birthday'] ?>">
      <small class="text-error"><?= HTML::esc($validations['birthday']) ?></small>
    </p>
    <p>
      <label for="photo">Foto</label>
      <input type="file" name="photo" id="photo" class="<?= $status['photo'] ?>">
      <small class="text-error"><?= HTML::esc($validations['photo']) ?></small>
    </p>
    <p>
      <label for="notes">Notas</label>
      <textarea name="notes" id="notes" cols="48" rows="4" placeholder="Ingresa notas adicionales sobre el contacto" class="<?= $status['notes'] ?>"><?= HTML::esc($values['notes']) ?></textarea>
      <small class="text-error"><?= HTML::esc($validations['notes']) ?></small>
    </p>
    <p class="text-right mt-auto">
      <a href="<?= URL::event(['contacts', $contactId], "contactShow_{$contactId}", "contactUpdate_{$contactId}") ?>" target=htmz class="button error">Cancelar</a>
      <input type="submit" value="Guardar" class="button success">
    </p>
  </form>
</div>
<?php if ($event !== "contactUpdate_{$contactId}") { ?>
<?php $app->render('templates/dashboard_close', ['app' => $app]) ?>
<?php } ?>
